package mylittleinvestigations;

import mylittleinvestigations.DialogCutscenes.DialogCutsceneAnimation;
import mylittleinvestigations.EasingFunctions.EasingFunction;

public class State
{
    private State cachedState;
    private int cachedActionIndex;
    private int actionIndex;
    private int previousActionIndex;

    public State()
    {
        this.cachedState = null;
        this.cachedActionIndex = -1;
        this.actionIndexSet = false;
        this.lastNavigationDirection = DirectNavigationDirection.None;
    }

    public int getActionIndex()
    {
        return this.actionIndex;
    }

    public void setActionIndex(int actionIndex)
    {
        this.previousActionIndex = this.actionIndex;
        this.actionIndex = actionIndex;
        this.setActionIndexSet(true);
    }

    public int getPreviousActionIndex() { return this.previousActionIndex; }
    private void setPreviousActionIndex(int previousActionIndex) { this.previousActionIndex = previousActionIndex; }

    private boolean actionIndexSet;

    public boolean getActionIndexSet() { return this.actionIndexSet; }
    private void setActionIndexSet(boolean actionIndexSet) { this.actionIndexSet = actionIndexSet; }

    private String leftCharacterId;

    public String getLeftCharacterId() { return this.leftCharacterId; }
    public void setLeftCharacterId(String leftCharacterId) { this.leftCharacterId = leftCharacterId; }

    private String leftCharacterEmotionId;

    public String getLeftCharacterEmotionId() { return this.leftCharacterEmotionId; }
    public void setLeftCharacterEmotionId(String leftCharacterEmotionId) { this.leftCharacterEmotionId = leftCharacterEmotionId; }

    private boolean isLeftCharacterTalking;

    public boolean getIsLeftCharacterTalking() { return this.isLeftCharacterTalking; }
    public void setIsLeftCharacterTalking(boolean isLeftCharacterTalking) { this.isLeftCharacterTalking = isLeftCharacterTalking; }

    private boolean shouldLeftCharacterChangeMouth;

    public boolean getShouldLeftCharacterChangeMouth() { return this.shouldLeftCharacterChangeMouth; }
    public void setShouldLeftCharacterChangeMouth(boolean shouldLeftCharacterChangeMouth) { this.shouldLeftCharacterChangeMouth = shouldLeftCharacterChangeMouth; }

    private int leftCharacterMouthOffCount;

    public int getLeftCharacterMouthOffCount() { return this.leftCharacterMouthOffCount; }
    public void setLeftCharacterMouthOffCount(int leftCharacterMouthOffCount) { this.leftCharacterMouthOffCount = leftCharacterMouthOffCount; }

    private EasingFunction leftCharacterXOffsetEasingFunction;

    public EasingFunction getLeftCharacterXOffsetEasingFunction() { return this.leftCharacterXOffsetEasingFunction; }
    public void setLeftCharacterXOffsetEasingFunction(EasingFunction leftCharacterXOffsetEasingFunction) { this.leftCharacterXOffsetEasingFunction = leftCharacterXOffsetEasingFunction; }

    private String leftReplacementCharacterId;

    public String getLeftReplacementCharacterId() { return this.leftReplacementCharacterId; }
    public void setLeftReplacementCharacterId(String leftReplacementCharacterId) { this.leftReplacementCharacterId = leftReplacementCharacterId; }

    private String leftReplacementCharacterEmotionId;

    public String getLeftReplacementCharacterEmotionId() { return this.leftReplacementCharacterEmotionId; }
    public void setLeftReplacementCharacterEmotionId(String leftReplacementCharacterEmotionId) { this.leftReplacementCharacterEmotionId = leftReplacementCharacterEmotionId; }

    private EasingFunction leftReplacementCharacterXOffsetEasingFunction;

    public EasingFunction getLeftReplacementCharacterXOffsetEasingFunction() { return this.leftReplacementCharacterXOffsetEasingFunction; }
    public void setLeftReplacementCharacterXOffsetEasingFunction(EasingFunction leftReplacementCharacterXOffsetEasingFunction) { this.leftReplacementCharacterXOffsetEasingFunction = leftReplacementCharacterXOffsetEasingFunction; }

    private String rightCharacterId;

    public String getRightCharacterId() { return this.rightCharacterId; }
    public void setRightCharacterId(String rightCharacterId) { this.rightCharacterId = rightCharacterId; }

    private String rightCharacterEmotionId;

    public String getRightCharacterEmotionId() { return this.rightCharacterEmotionId; }
    public void setRightCharacterEmotionId(String rightCharacterEmotionId) { this.rightCharacterEmotionId = rightCharacterEmotionId; }

    private boolean isRightCharacterTalking;

    public boolean getIsRightCharacterTalking() { return this.isRightCharacterTalking; }
    public void setIsRightCharacterTalking(boolean isRightCharacterTalking) { this.isRightCharacterTalking = isRightCharacterTalking; }

    private boolean shouldRightCharacterChangeMouth;

    public boolean getShouldRightCharacterChangeMouth() { return this.shouldRightCharacterChangeMouth; }
    public void setShouldRightCharacterChangeMouth(boolean shouldRightCharacterChangeMouth) { this.shouldRightCharacterChangeMouth = shouldRightCharacterChangeMouth; }

    private int rightCharacterMouthOffCount;

    public int getRightCharacterMouthOffCount() { return this.rightCharacterMouthOffCount; }
    public void setRightCharacterMouthOffCount(int rightCharacterMouthOffCount) { this.rightCharacterMouthOffCount = rightCharacterMouthOffCount; }

    private EasingFunction rightCharacterXOffsetEasingFunction;

    public EasingFunction getRightCharacterXOffsetEasingFunction() { return this.rightCharacterXOffsetEasingFunction; }
    public void setRightCharacterXOffsetEasingFunction(EasingFunction rightCharacterXOffsetEasingFunction) { this.rightCharacterXOffsetEasingFunction = rightCharacterXOffsetEasingFunction; }

    private String rightReplacementCharacterId;

    public String getRightReplacementCharacterId() { return this.rightReplacementCharacterId; }
    public void setRightReplacementCharacterId(String rightReplacementCharacterId) { this.rightReplacementCharacterId = rightReplacementCharacterId; }

    private String rightReplacementCharacterEmotionId;

    public String getRightReplacementCharacterEmotionId() { return this.rightReplacementCharacterEmotionId; }
    public void setRightReplacementCharacterEmotionId(String rightReplacementCharacterEmotionId) { this.rightReplacementCharacterEmotionId = rightReplacementCharacterEmotionId; }

    private EasingFunction rightReplacementCharacterXOffsetEasingFunction;

    public EasingFunction getRightReplacementCharacterXOffsetEasingFunction() { return this.rightReplacementCharacterXOffsetEasingFunction; }
    public void setRightReplacementCharacterXOffsetEasingFunction(EasingFunction rightReplacementCharacterXOffsetEasingFunction) { this.rightReplacementCharacterXOffsetEasingFunction = rightReplacementCharacterXOffsetEasingFunction; }

    private DirectNavigationDirection lastNavigationDirection;

    public DirectNavigationDirection getLastNavigationDirection() { return this.lastNavigationDirection; }
    public void setLastNavigationDirection(DirectNavigationDirection lastNavigationDirection) { this.lastNavigationDirection = lastNavigationDirection; }

    private boolean endRequested;

    public boolean getEndRequested() { return this.endRequested; }
    public void setEndRequested(boolean endRequested) { this.endRequested = endRequested; }

    private boolean exitRequested;

    public boolean getExitRequested() { return this.exitRequested; }
    public void setExitRequested(boolean exitRequested) { this.exitRequested = exitRequested; }

    private boolean presentWrongEvidenceRequested;

    public boolean getPresentWrongEvidenceRequested() { return this.presentWrongEvidenceRequested; }
    public void setPresentWrongEvidenceRequested(boolean presentWrongEvidenceRequested) { this.presentWrongEvidenceRequested = presentWrongEvidenceRequested; }

    private boolean preserveBgm;

    public boolean getPreserveBgm() { return this.preserveBgm; }
    public void setPreserveBgm(boolean preserveBgm) { this.preserveBgm = preserveBgm; }

    private DialogCutsceneAnimation currentAnimation;

    public DialogCutsceneAnimation getCurrentAnimation() { return this.currentAnimation; }
    public void setCurrentAnimation(DialogCutsceneAnimation currentAnimation) { this.currentAnimation = currentAnimation; }

    private Conversation currentConversation;

    public Conversation getCurrentConversation() { return this.currentConversation; }
    public void setCurrentConversation(Conversation currentConversation) { this.currentConversation = currentConversation; }
    
    public Confrontation getCurrentConfrontation() { return (Confrontation)this.currentConversation; }

    private ConfrontationTopic currentConfrontationTopic;

    public ConfrontationTopic getCurrentConfrontationTopic() { return this.currentConfrontationTopic; }
    public void setCurrentConfrontationTopic(ConfrontationTopic currentConfrontationTopic) { this.currentConfrontationTopic = currentConfrontationTopic; }

    private String newAreaRequested;

    public String getNewAreaRequested() { return this.newAreaRequested; }
    public void setNewAreaRequested(String newAreaRequested) { this.newAreaRequested = newAreaRequested; }

    private String newLocationRequested;

    public String getNewLocationRequested() { return this.newLocationRequested; }
    public void setNewLocationRequested(String newLocationRequested) { this.newLocationRequested = newLocationRequested; }

    private String transitionId;

    public String getTransitionId() { return this.transitionId; }
    public void setTransitionId(String transitionId) { this.transitionId = transitionId; }

    public void ClearActionIndexSet()
    {
        this.setActionIndexSet(false);
    }

    public State CreateCachedState()
    {
        State state = new State();

        state.setLeftCharacterId(this.getLeftCharacterId());
        state.setLeftCharacterEmotionId(this.getLeftCharacterEmotionId());
        state.setRightCharacterId(this.getRightCharacterId());
        state.setRightCharacterEmotionId(this.getRightCharacterEmotionId());

        return state;
    }

    public void CacheState()
    {
        this.cachedState = this.CreateCachedState();
    }

    public void CachePreviousActionIndex()
    {
        this.cachedActionIndex = this.getPreviousActionIndex();
    }

    public void RestoreFromState(State state)
    {
        if (state != null)
        {
            this.setLeftCharacterId(state.getLeftCharacterId());
            this.setLeftCharacterEmotionId(state.getLeftCharacterEmotionId());
            this.setRightCharacterId(state.getRightCharacterId());
            this.setRightCharacterEmotionId(state.getRightCharacterEmotionId());
        }
    }

    public void RestoreCachedState()
    {
        this.RestoreFromState(this.cachedState);
        this.DeleteCachedState();
    }

    public void DeleteCachedState()
    {
        this.cachedState = null;
    }

    public void RestoreActionIndexFromCache()
    {
        if (this.cachedActionIndex >= 0)
        {
            this.setActionIndex(this.cachedActionIndex);
        }

        this.cachedActionIndex = -1;
    }

    public void ResetForConversation()
    {
        this.setActionIndex(0);
        this.setIsLeftCharacterTalking(false);
        this.setShouldLeftCharacterChangeMouth(false);
        this.setLeftCharacterMouthOffCount(0);
        this.setIsRightCharacterTalking(false);
        this.setShouldRightCharacterChangeMouth(false);
        this.setRightCharacterMouthOffCount(0);
        this.setEndRequested(false);
        this.setPresentWrongEvidenceRequested(false);
        this.setPreserveBgm(false);
        this.setNewAreaRequested(null);
        this.setNewLocationRequested(null);
        this.setTransitionId(null);
        this.DeleteCachedState();
    }
}
